<template>
    <div class="" id="facMaintain">
      <div class="permission-content bg-purple user-table" >
          <el-form :inline="true" size="medium"  ref="form" :model="form" label-width="160px" style="position:relative;">
          
                <el-form-item label="保养单号" >
                  <el-input v-model="form.repairBill"></el-input>
                </el-form-item>
                  <el-form-item label="保养日期" >
                  <el-input v-model="form.maintainDate"></el-input>
                </el-form-item>
                  <el-form-item label="设备档案号" >
                    <el-input v-model="form.deviceNumber"></el-input>
                </el-form-item>
                  <el-form-item label="发起人" >
                     <el-input v-model="form.initiator"></el-input>
                </el-form-item>
                  <el-form-item label="当前设备所属单位" >
                     <el-input v-model="form.company"></el-input>
                </el-form-item>
                  <el-form-item label="设备名称" >
                     <el-input v-model="form.facName"></el-input>
                </el-form-item>
                  <el-form-item label="设备编号" >
                     <el-input v-model="form.facCode"></el-input>
                </el-form-item>
                 <el-form-item label="设备类型" >
                     <el-input v-model="form.deviceType"></el-input>
                </el-form-item>
                  <el-form-item label="最近保养记录" >

                     <el-input v-model="form.maintainRecord[form.maintainRecord.length-1].maintainDate"></el-input>
                </el-form-item>
                  <el-form-item label="图片" >
                    <el-input v-model="form.img"></el-input>
                </el-form-item>
                  <el-form-item  :class="role=='admin'?'':'hidden'" label="经办人" >
                     <el-input v-model="form.operator" @focus="dialogOperator=true"></el-input>
                </el-form-item>
                <el-form-item  label="保养内容" >
                   <el-input v-model="form.mainContent"></el-input>
                </el-form-item>
                <el-form-item label="金额" >
                  <el-input v-model="form.money"></el-input>
                </el-form-item>
                <div style="position:absolute;right:40px;bottom:30px;">
                  <el-button v-preventReClick type="primary" @click="submitMaintain(form)">确 定</el-button>
                  <el-button v-preventReClick type="primary" @click="cancel()">取消</el-button>
                </div>
               
                  

          </el-form>
          <el-dialog :close-on-click-modal="false"  title="保养人员" :visible.sync="dialogOperator">
          <el-input
            placeholder="输入关键字进行过滤"
            v-model="filterText">
          </el-input>
           <el-tree
            class="filter-tree"
            :data="operTree"
            :props="defaultProps"
            default-expand-all
            :filter-node-method="filterNode"
            @node-click="nodeClick"
            ref="tree">
          </el-tree>
          </el-dialog>
      </div>
    </div>
</template>
<script>
// import { defineComponent } from '@vue/composition-api'
import { submitMaintain} from '@/api/facility/facility'
import { getOperator} from '@/api/user'

export default {
    data() {
      return{
          text:"测试",
          tableData:[],
          formData:{},
          form: {
         
        },
        operTree:[],
        defaultProps: {
          children: 'children',
          label: 'label'
        },
        filterText:'',
        dialogOperator:false,
          show:false,
          edit:false,
          role:'admin'          
      }  
    },
    watch:{
      filterText(val){
        this.$refs.tree.filter(val)
      },
    },
    created(){
      this.getOperator()
      this.form=this.$route.params
      console.log(this.form.maintainRecord[this.form.maintainRecord.length-1])
      this.edit=this.$route.params.edit
      this.role=this.$store.state.user.roles[0]

    },
    mounted(){
    },
    methods:{
      //获取维修人员
      getOperator(){
        getOperator().then(res=>{
          this.operTree=res.data
        })
      },
      //删选节点
      filterNode(value, data) {
        if (!value) return true;
        return data.label.indexOf(value) !== -1;
      },
      nodeClick(data){
        this.form.operator=data.label
        this.dialogOperator=false
      },
      submitMaintain(data) {
          submitMaintain(data).then(res=>{
          this.$message({
          message: '提交成功,等待审批中',
          type: 'success'
        });
        this.$router.back()
        })
        
        
    

      },
     
    }
}
</script>
<style lang='scss' scoped>
#facMaintain{
    .el-form{
      padding: 20px;
      height: calc(100vh - 50px);
    }
}
.hidden{
  display: none;
}

</style>